package wc;

public class CheckInput {
	String[] input = null;

	CheckInput(String[] input) {
		this.input = input;
	}

	public boolean cheak() {// 检测用户输入是否合法
		boolean pass = false;// 用于标记输入是否合法
		for (String choice : input) {
			if (choice.startsWith("-")) {
				if (choice.length() != 2) {
					return false;
				}
				//int begin = choice.indexOf(1);
				String partOfChoice = choice.substring(1);
			
				switch (partOfChoice) {
				case "s":
					pass = true;
					break;
				case "a":
					pass = true;
					break;
				case "c":
				
					pass = true;
					break;
				case "l":
					pass = true;
					break;
				case "w":
					pass = true;
					break;
				case "x":
					if (input.length == 1) {
						pass = true;
					}else {
						System.out.println("-x 参数只能单独使用");
					}
					break;
				case "e":// 检测-e选项是否搭配有-s选项和需要停用的词表
					for (String cell : input) {
						if (cell.equals("-s")) {				
									pass = true;
									break;
						}else {
							System.out.println("缺少参数-s");
							return false;
						}

					}

					break;
				case "o":
					pass = true;
					break;
				default:
					System.out.println("选项格式不正确");
					return false;
				}
			} else if (choice.startsWith("*")) {// 处理通配符的格式
				boolean isExistS = false;// 因为通配符只能搭配-s使用
				for (String cell : input) {
					if (cell.equals("-s")) {
						isExistS = true;
						break;
					}
				}
				if (isExistS == false) {
					System.out.println("缺少参数：-s");
					return false;
				}
				if (choice.equals("*.txt") || choice.equals("*.c") || choice.equals("*.doc")
						|| choice.equals(".java")) {
					pass = true;
				} else {
					System.out.println("通配符格式超出范围（格式范围：.txt/.java/.c/.doc）");
					return false;
				}
			} else if (choice.endsWith(".txt")||choice.endsWith(".c")||choice.endsWith(".java")||choice.endsWith(".doc")) {
				pass = true;
				
			} else {
				System.out.println("非法输入");
				return false;
			}
		}
		return pass;
	}
}
